<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php echo $this->breadCrumbs(); ?>
  </div>
  <?php if (isset($error_warning)) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/information.png" alt="" /> <?php echo $_['heading_title']; ?></h1>
      <div class="buttons">
	  <a onclick="location = '<?php echo UA('catalog/faq/insert'); ?>'" class="button"><?php echo $_['button_insert']; ?></a>
	  <a onclick="$('form').submit();" class="button"><?php echo $_['button_delete']; ?></a></div>
    </div>
    <div class="content">
      <form action="<?php echo UA('catalog/faq/delete'); ?>" method="post" enctype="multipart/form-data" id="form">
        <table class="J_tablelist list" data-acturi="<?php echo UA('catalog/faq/smartedit');?>">
          <thead>
            <tr>
              <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
			 <td class="left">
                <a <?php echo sort_url('r.author'); ?>><?php echo $_['column_author']; ?></a>
             </td>
			 <td class="left">
                <a <?php echo sort_url('pd.name'); ?>><?php echo $_['column_question']; ?></a>
             </td>
             <td class="left"><?php echo $_['column_answer'];?></td>
              <td class="center">
                <a <?php echo sort_url('r.status'); ?>><?php echo $_['column_status']; ?></a>
              </td>
              <td class="left">
                <a <?php echo sort_url('r.date_added', true); ?>><?php echo $_['column_date_added']; ?></a>
              </td>
              <td class="right"><?php echo $_['column_action']; ?></td>
            </tr>
          </thead>
          <tbody>
            <tr class="filter">
              <td></td>
			  <td><input type="text" name="filter_author" value="<?php echo $filter_author; ?>" size="12"/></td>
              <td><input type="text" name="filter_product_id" value="<?php echo $filter_product_id; ?>"  size="12" title="Product ID"/></td>              
              <td></td>
              <td class="center"><select name="filter_status">
                  <option value="*"></option>
				  <?php echo form_select_option($_['option_statuses'], $filter_status, true);?>
                </select></td>
              <td><input type="text" class="date" name="filter_date_added" value="<?php echo $filter_date_added; ?>" size="12"/></td>
              <td align="right"><a onclick="filter();" class="button"><?php echo $_['button_filter']; ?></a></td>
            </tr>
            <?php if ($faqs) { ?>
            <?php foreach ($faqs as $faq) { ?>
            <tr onmouseover="this.className='on';" onmouseout="this.className='';">
              <td style="text-align: center;">
                <input type="checkbox" name="selected[]" value="<?php echo $faq['faq_id']; ?>" />
              </td>
			  <td class="left">
			  <span data-tdtype="edit" data-field="author" data-id="<?php echo $faq['faq_id'];?>"><?php echo $faq['author']; ?></span>
			  <small class="help"><?php echo $faq['email'];?></small>
			  </td>
              <td class="left">
				<?php echo nl2br($faq['question']); ?>
				<small class="help"><a href="<?php echo U('product/product', 'product_id=' . $faq['product_id']);?>" target="_blank"><?php echo $faq['name']; ?></a></small>
			  </td>              
              <td class="left"><?php echo nl2br($faq['answer'])?></td>
              <td class="center">
               <img class="cur" src="view/image/<?php echo $faq['status'] ? 'enabled' : 'disabled'; ?>.png" data-tdtype="toggle"
               data-field="status" data-id="<?php echo $faq['faq_id'];?>" data-value="<?php echo $faq['status']; ?>" title="toggle status"></td>
              <td class="left"><?php echo v5_date_format($faq['date_added'], 'Y-m-d H:i'); ?></td>
              <td class="right">
                [ <a href="<?php echo UA('catalog/faq/update', 'faq_id=' . $faq['faq_id']); ?>"><?php echo $_['text_edit']; ?></a> ]
              </td>
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="7"><?php echo $_['text_no_results']; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<script>
function filter() {
	url = '<?php echo UA('catalog/faq', 'filter_reset=1'); ?>';

	var v = $('input[name=\'filter_product_id\']').attr('value');
	if (v) {
		url += '&filter_product_id=' + encodeURIComponent(v);
	}

	v = $('input[name=\'filter_author\']').attr('value');
	if (v) {
		url += '&filter_author=' + encodeURIComponent(v);
	}

	v = $('select[name=\'filter_status\']').attr('value');
	if (v != '*') {
		url += '&filter_status=' + encodeURIComponent(v);
	}

	v = $('input[name=\'filter_date_added\']').attr('value');
	if (v != '') {
		url += '&filter_date_added=' + encodeURIComponent(v);
	}
	location = url;
}
$('.date').datepicker({dateFormat: 'yy-mm-dd'});

$('.J_tablelist').listTable();
</script>
<?php echo $footer; ?>